<template>
  <div>
    <h1>人员列表</h1>
    <input type="text" v-model="name" placeholder="请输入名字..." />
    <button @click="add">添加</button>
    <ul>
      <li v-for="p of personList" :key="p.id">{{ p.name }}</li>
    </ul>
    <h3 style="color:red">Count组件的和为: {{sum}}</h3>
  </div>
</template>

<script>
import { nanoid } from 'nanoid';

export default {
  name: "myPerson",
  data() {
    return {
      name:''
    }
  },
  computed: {
    personList() {
      return this.$store.state.personList;
    },
    sum(){
      return this.$store.state.sum
    }
  },
  methods: {
    add(){
       const p = {id:nanoid(),name:this.name}
       this.$store.commit('AddPerson',p)
       this.name = ''
    }
  },
};
</script>

<style></style>
